/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package openaccessagrotagtagger;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.io.*;
import java.util.*;

/**
 *
 * @author root
 */
public class UpdateContentTypeBookChapter {

    public boolean updateContentTypeBookChapterAgrotagKeywords(int nid, String tagSet)
    {

        boolean returnValue = false;

        Connection conn = null;
        Statement stmt_update = null;


        try {

            /*  Register the driver
		The following Class.forName() statement is not necessary if using Java SE 6 (1.6) or later */


            Class.forName("com.mysql.jdbc.Driver").newInstance();

            try {

//                System.out.println("Haribol check!!!!!!!!  2");
		/* Get a connection to the database */
                conn = DriverManager.getConnection(OpenAccessAgrotagTagger.dbPath);

//                System.out.println("Haribol check!!!!!!!!  3");

                try {
//                    System.out.println("Haribol check!!!!!!!!  4");
                    stmt_update = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

                    String sqlCommand = "UPDATE content_type_book_chapter SET field_chapter_agro_tags_value =\"" + tagSet + "\"" + " WHERE nid=" + nid;
                    System.out.println("sqlUpdateCommand::::" + sqlCommand);
                    stmt_update.executeUpdate(sqlCommand);
                    returnValue = true;
                }
                catch (Exception ex)
                {
                    System.out.println("Exception here :" + ex);
                }

                finally {

                    if (stmt_update != null) {
                        try {
                            stmt_update.close();
                        } catch (SQLException sqlEx) {
                               System.out.println("SQLException: " + sqlEx.getMessage());
                        }

                        stmt_update = null;
                    }

                    if (conn != null) {
                        try {
                            conn.close();
                        } catch (SQLException sqlEx) {
                               // Ignore
                        }

                        conn = null;
                    }

                }

            } catch (SQLException ex) {
//                System.out.println("SQLException HariBol Check: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
            }

        } catch (Exception ex) {
            System.out.println("Exception: " + ex.getMessage());
        }


        return returnValue;
    }

}


